﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PluginFramework.Plugins;

namespace MvcApplication.Controllers
{
    public class PluginsController : Controller
    {
        //
        // GET: /Plugins/

        public ActionResult Index()
        {
        	ViewBag.Plugins = MvcApplication.Packages.PluginsManagement.GetAvailablePlugins();
			return View();
        }

    	[HttpPost]
    	public ActionResult Index(PluginStateUpdater[] plugins)
    	{
			var al = MvcApplication.ActivePlugins;
			al.StateManager.UpdateState(plugins);
			//create instances for enabled plugins
			foreach(var p in plugins.Where(d=>d.IsActive))
			{
				if (p.IsActive) al.CreateInstance(p.Id);				
			}
    		return RedirectToAction("index","home");
    	}

    	public ActionResult Packages()
    	{
    		ViewBag.Packages = MvcApplication.Packages.GetAvailablePackages();
			
    		return View();
    	}
    }
}
